home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++ FAQ Reference 1.0 / C++ FAQ Reference 1.0.rsrc / TEXT_928.txt < prev    next >
Encoding:
Text File  |  1993-06-30  |  721 b   |  9 lines

  1. A program is 'const correct' if it never mutates a constant object.  This is achieved by using the keyword 'const'.  Ex: 
  2. if you pass a String to a function 'f()', and you wish to prohibit 'f()' from modifying the original String, you:
  3. can either pass by value:    void  f(      String  s   )  { /*...*/ }
  4. or by constant reference:    void  f(const String& s   )  { /*...*/ }
  5. or by constant pointer:    void  f(const String* sptr)  { /*...*/ }
  6. but *not* by non-const ref:    void  f(      String& s   )  { /*...*/ }
  7. *nor* by non-const pointer: void  f(      String* sptr)  { /*...*/ }
  8.  
  9. Attempted changes to 's' within a fn that takes a 'const String&' are flagged as compile-time errors; neither run-time space nor speed is degraded.